//
//  BidHistoryViewController.swift
//  cxd4iphone
//
//  Created by hexy on 12/3/15.
//  Copyright © 2015 hexy. All rights reserved.
//

import UIKit

class BidInvestRecordViewController: BaseTableViewController {

    private lazy var bidInvestRecordListViewModel = BidInvestRecordListViewModel()
    
    var bidID = String()
    
    init(bidID: String) {
        
        super.init(style: .Plain)
        
        self.title = "投资记录"
        self.bidID = bidID
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
        
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        loadData()
    }
    
    private func loadData() {
        
        xx_showHUD(nil)
        bidInvestRecordListViewModel.loadBidList(self.bidID, pullDown: true).subscribeError({ (error) -> Void in
            
                xx_showError(error)
            
            }) { () -> Void in
                
                xx_hideHUD()
                self.tableView.reloadData()
        }
    }
    override func makeTableView() {
        
        tableView.sectionHeaderHeight = xx_height(50)
        
        self.tableListViewModel = bidInvestRecordListViewModel
        
        tableView.registerClass(BidInvestRecordListCell.self, forCellReuseIdentifier: BidInvestRecordCellReuseID)

    }
}

extension BidInvestRecordViewController {
    
    override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        
        
        return BidInvestRecordSectionHeaderView()
    }

}